<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机创建</title>
  <link rel="shortcut icon" href="../img/favicon.ico" type="image/x-icon">
  <style>
    * {padding: 0; margin: 0; font: inherit; box-sizing: border-box;
      -webkit-tap-highlight-color: transparent;
      -webkit-overflow-scrolling: touch;
      -webkit-text-size-adjust: 100%;
    }
    html, body {height: 100%;}
    #app {height: 100%; overflow: hidden;}
    #app canvas {width: 100%; height: 100%; vertical-align: top;}
    #app canvas:focus {background: #f3fbff;}
  </style>
</head>
<body>
  
<div id="app">
  <canvas id="canvas" tabindex="1"></canvas>
</div>

<script src="../lib/app-aux.js"></script>
<script type="module">
import BrainGraphControl from '../lib/lib-brain-graph-control.js'

const data = Array(10e4).fill().map((_, idx, arr) => {
  const id = idx + 1
  return {
    id,
    pid: 0,
    name: id + '',
    depth: rand(0, arr.length)
  }
})

for (let i = data.length - 1; i > -1; i--) {
  for (let j = i - 1; j > -1; j--) {
    if (data[j].depth < data[i].depth) {
      data[i].pid = data[j].id
      break
    }
  }
}

data.push({id: 0, pid: -1, name: 'root'})

const timeText = `压力测试 ${parseInt(data.length / 1e4)}万节点 执行耗时`
document.title = timeText
console.time(timeText)
const brainGraph = window.brainGraph = new BrainGraphControl({
  canvas: document.getElementById('canvas'),
  data,
})
console.timeEnd(timeText)

const d = window.d = brainGraph.d
</script>

</body>
</html>